package com.ebelter.seneo.ui.activitys;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;

import com.ebelter.btcomlib.utils.activity_manager.ActivityManagers;
import com.ebelter.seneo.R;
import com.ebelter.seneo.utils.SeneoUtils;

import java.util.Map;

public class EmptyActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Uri uri = getIntent().getData();

        if (uri != null) {
            // 完整的url信息
            String url = uri.toString();
            Log.i("FitbitActivity", "---getIntent().getData()--url: " + url);
            final String resultParameter = url.substring(url.indexOf("#")+1);
            Log.i("FitbitActivity", "带回来的参数-->" + resultParameter);
            recordParameter(resultParameter);
        }

        ActivityManagers.getInstance().closeActivity("FitbitActivity");
        startActivity(new Intent(this,FitbitActivity.class));
        finish();
    }

    private Map<String,String> parameterMap = new ArrayMap<>();
    //记录参数
    private void recordParameter(String resultParameter) {

        String[] par=resultParameter.split("&");
        parameterMap.clear();

        for (int i=0;i<par.length;i++){
            String[] subR = par[i].split("=");
            String key = subR[0];
            String value = subR[1];

            Log.i("FitbitActivity", "解析回来的子参数" + key+" = "+value);
            parameterMap.put(key,value);

            if (TextUtils.equals("access_token",key)){
                SeneoUtils.setFitbitToken(value);
            }
            //access_token = "12"
            //user_id = 7MMTLJ
            //scope = weight
            //token_type = Bearer
            //expires_in = 31532031
        }
    }
}
